feat: add spring-boot-testing skill for Spring Boot 4.0#1085
feat: add spring-boot-testing skill for Spring Boot 4.0#1085aaronpowell merged 1 commit intogithub:stagedfrom
Conversation
- Introduced MockMvcTester for AssertJ-style assertions in Spring MVC testing. - Added @restclienttest for testing REST clients with MockRestServiceServer. - Implemented RestTestClient as a modern alternative to TestRestTemplate. - Documented migration steps from Spring Boot 3.x to 4.0, including dependency and annotation changes. - Created an overview of test slices to guide testing strategies. - Included Testcontainers setup for JDBC testing with PostgreSQL and MySQL. - Enhanced @WebMvcTest documentation with examples for various HTTP methods and validation.
There was a problem hiding this comment.
Pull request overview
Adds a new spring-boot-testing skill to the repository to provide reference-driven guidance for testing Spring Boot 4 applications, including test slices, modern Spring testing APIs, Testcontainers usage, and migration notes.
Changes:
- Introduces the new
skills/spring-boot-testing/skill with aSKILL.mdentry point and a set of focused reference pages. - Documents Spring MVC testing patterns (MockMvcTester / classic MockMvc), REST client testing (@restclienttest, RestTestClient), and data layer testing (@DataJpaTest + Testcontainers).
- Updates
docs/README.skills.mdto register the new skill and list its reference files.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| skills/spring-boot-testing/SKILL.md | Skill entry point and index of references, principles, and dependency snippets |
| skills/spring-boot-testing/references/webmvctest.md | @WebMvcTest slice guidance and example patterns |
| skills/spring-boot-testing/references/testcontainers-jdbc.md | Testcontainers JDBC setup patterns for real DB testing |
| skills/spring-boot-testing/references/test-slices-overview.md | Decision matrix and quick selection guide for test slices |
| skills/spring-boot-testing/references/sb4-migration.md | Migration-oriented notes for Spring Boot 4 testing changes |
| skills/spring-boot-testing/references/resttestclient.md | RestTestClient reference and migration examples |
| skills/spring-boot-testing/references/restclienttest.md | @RestClientTest patterns with MockRestServiceServer |
| skills/spring-boot-testing/references/mockmvc-tester.md | MockMvcTester fluent assertion patterns |
| skills/spring-boot-testing/references/mockmvc-classic.md | Legacy MockMvc patterns and migration pointers |
| skills/spring-boot-testing/references/mockitobean.md | @MockitoBean usage patterns and migration from @MockBean |
| skills/spring-boot-testing/references/instancio.md | Instancio-based test data generation patterns |
| skills/spring-boot-testing/references/datajpatest.md | @DataJpaTest slice patterns including Testcontainers usage |
| skills/spring-boot-testing/references/context-caching.md | TestContext caching concepts and performance tips |
| skills/spring-boot-testing/references/assertj-collections.md | AssertJ collection assertion cookbook |
| skills/spring-boot-testing/references/assertj-basics.md | AssertJ core assertion patterns and exception assertions |
| docs/README.skills.md | Registers the new skill in the repo’s skill index |
You can also share your feedback on Copilot code review. Take the survey.
| } | ||
|
|
||
| @Test | ||
| void anonymousUserShouldBeForbidden() { |
| restClient | ||
| .get() | ||
| .uri("/orders/1") | ||
| .exchange() | ||
| .expectStatus() | ||
| .isOk() // 200 | ||
| .isCreated() // 201 | ||
| .isNoContent() // 204 | ||
| .isBadRequest() // 400 | ||
| .isNotFound() // 404 | ||
| .is5xxServerError() // 5xx | ||
| .isEqualTo(200); // Specific code |
| ## Testcontainers 2.0 | ||
|
|
||
| Module naming changed: | ||
|
|
||
| **Before (1.x):** | ||
|
|
||
| ```xml | ||
| <artifactId>postgresql</artifactId> | ||
| ``` | ||
|
|
||
| **After (2.0):** | ||
|
|
||
| ```xml | ||
| <artifactId>testcontainers-postgresql</artifactId> | ||
| ``` |
| ## Java 25 Features in Tests | ||
|
|
||
| ### Records for Test Data | ||
|
|
||
| ```java | ||
| record OrderRequest(String product, int quantity) {} | ||
| record OrderResponse(Long id, String status, BigDecimal total) {} | ||
| ``` |
| @@ -0,0 +1,189 @@ | |||
| --- | |||
| name: spring-boot-testing | |||
| description: Expert Spring Boot 4 testing specialist that selects the best Spring Boot testing techniques for your situation with Junit 6 and AssertJ. | |||
| ```xml | ||
| <!-- WebMvcTest --> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-webmvc-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <!-- DataJpaTest --> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-data-jpa</artifactId> | ||
| </dependency> | ||
|
|
||
| <!-- RestClientTest --> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-restclient-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> |
| 3. Clear() the entity manager to test lazy loading | ||
| 4. Use real database (Testcontainers) for accurate results | ||
| 5. Test both success and failure cases | ||
| 6. Leverage Java 25 var keyword for cleaner variable declarations |
| ```xml | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-testcontainers</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>testcontainers-postgresql</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> |
| @@ -0,0 +1,189 @@ | |||
| --- | |||
| name: spring-boot-testing | |||
| description: Expert Spring Boot 4 testing specialist that selects the best Spring Boot testing techniques for your situation with Junit 6 and AssertJ. | |||
| | [shuffle-json-data](../skills/shuffle-json-data/SKILL.md) | Shuffle repetitive JSON objects safely by validating schema consistency before randomising entries. | None | | ||
| | [snowflake-semanticview](../skills/snowflake-semanticview/SKILL.md) | Create, alter, and validate Snowflake semantic views using Snowflake CLI (snow). Use when asked to build or troubleshoot semantic views/semantic layer definitions with CREATE/ALTER SEMANTIC VIEW, to validate semantic-view DDL against Snowflake via CLI, or to guide Snowflake CLI installation and connection setup. | None | | ||
| | [sponsor-finder](../skills/sponsor-finder/SKILL.md) | Find which of a GitHub repository's dependencies are sponsorable via GitHub Sponsors. Uses deps.dev API for dependency resolution across npm, PyPI, Cargo, Go, RubyGems, Maven, and NuGet. Checks npm funding metadata, FUNDING.yml files, and web search. Verifies every link. Shows direct and transitive dependencies with OSSF Scorecard health data. Invoke with /sponsor followed by a GitHub owner/repo (e.g. "/sponsor expressjs/express"). | None | | ||
| | [spring-boot-testing](../skills/spring-boot-testing/SKILL.md) | Expert Spring Boot 4 testing specialist that selects the best Spring Boot testing techniques for your situation with Junit 6 and AssertJ. | `references/assertj-basics.md`<br />`references/assertj-collections.md`<br />`references/context-caching.md`<br />`references/datajpatest.md`<br />`references/instancio.md`<br />`references/mockitobean.md`<br />`references/mockmvc-classic.md`<br />`references/mockmvc-tester.md`<br />`references/restclienttest.md`<br />`references/resttestclient.md`<br />`references/sb4-migration.md`<br />`references/test-slices-overview.md`<br />`references/testcontainers-jdbc.md`<br />`references/webmvctest.md` | |
|
@all-contributors add @kartikdhiman for skills instructions |
|
I couldn't determine any contributions to add, did you specify any contributions? |
|
I couldn't determine any contributions to add, did you specify any contributions? |
|
@all-contributors add @kartikdhiman for skills instructions |
Pull Request Checklist
npm startand verified thatREADME.mdis up to date.Description
@WebMvcTest@DataJpaTest@RestClientTest@JsonTest@SpringBootTestType of Contribution
Additional Notes
By submitting this pull request, I confirm that my contribution abides by the Code of Conduct and will be licensed under the MIT License.